﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LServer.Core.Utils
{
    public class LFRedisHelp:RedisHelper
    {
        public static T LFCacheShell<T>(string key, string field, Func<string, T> getData) 
        {
            T t = HGet<T>(key, field);
            if (t == null) 
            {
                t = getData(field);
                HSet(key, field, t);
            }
            return t;
        }

        public static async Task<T> LFCacheShellAsync<T>(string key, string field, Func<string, Task<T>> getDataAsync) 
        {
            T t = await HGetAsync<T>(key, field);
            if (t == null)
            {
                t = await getDataAsync(field);
                await HSetAsync(key, field, t);
            }
            return t;
        }
    }
}
